import requests


class SinaFinance():
    domain = "https://vip.stock.finance.sina.com.cn"

    def __init__(self):
        pass

    def query_stock_count_by_type(self, type: str):
        response = requests.get(
            url=f"{self.domain}/quotes_service/api/json_v2.php/Market_Center.getRTHKStockCount?node={type}",
        )
        content = response.text
        try:
            return int(content.replace("\"", ""))
        except Exception as e:
            print(content)
            raise e

    def qery_stock_list_by_type(self, type: str, page: int, size: int):
        response = requests.get(
            url=f"https://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHKStockData?page={page}&num={size}&sort=symbol&asc=1&node={type}&_s_r_a=init"
        )
        return response.json()


if __name__ == "__main__":
    pass
